package com.longxiao.vo;

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.Map;

import com.longxiao.entity.StudentLecture;
import com.longxiao.entity.User;

/**
 * Created by yusong on 2017/5/4.
 * 学生用户信息
 */
public class StuUserVo extends UserVo{
	
	private String maxLevel = "C12";
    //学生等级
    private String level;
    //进度
    private String progress;
//    当前课程id
    private Integer courseId;
//    当前章节id
    private Integer chapterId;
    //已上课时
    private Integer consumedLectures;
    //可上课时
    private Integer balanceLectures;
    //冻结课时
    private Integer frozenLectures;
    //听力分数
    private BigDecimal listenScore;
    //口语分数
    private BigDecimal oralScore;
    //阅读分数
    private BigDecimal readScore;
//    评价总人数
    private Integer commentCount;
//    听力分数变动百分比
    private BigDecimal listenChange;
//    口语分数变动百分比
    private BigDecimal oralChange;
//    阅读分数变动百分比
    private BigDecimal readChange;

	// 任务信息
	private Map<String, Object> task;

    public StuUserVo() {
        super();
    }

    public StuUserVo(User user, StudentLecture studentLecture) {
        super(user);
        this.level = studentLecture.getLevel();
        this.progress = studentLecture.getProgress();
        this.consumedLectures = studentLecture.getConsumedLectures();
        this.balanceLectures = studentLecture.getBalanceLectures();
        this.frozenLectures = studentLecture.getFrozenLectures();
        this.listenScore = studentLecture.getAveListenScore();
        this.oralScore = studentLecture.getAveOralScore();
        this.readScore = studentLecture.getAveReadScore();
        this.commentCount = studentLecture.getCommentsCount();
        this.listenChange = this.getChange(studentLecture.getAveListenScore(),studentLecture.getAveListenScoreLast());
        this.oralChange = this.getChange(studentLecture.getAveOralScore(), studentLecture.getAveOralScoreLast());
        this.readChange = this.getChange(studentLecture.getAveReadScore(), studentLecture.getAveReadScoreLast());
        this.courseId = studentLecture.getCourseId();
        this.chapterId = studentLecture.getChapterId();
    }

	private BigDecimal getChange(BigDecimal curScore, BigDecimal lastScore) {
//		当前没有评分，返回0
		if(curScore.doubleValue() == 0) {
			return new BigDecimal("0");
		}
//		上次没有评分，返回1
		if(lastScore.doubleValue() == 0) {
			return new BigDecimal("1");
		}
		BigDecimal changed = curScore.subtract(lastScore).divide(lastScore,new MathContext(10));
		return changed.setScale(4, RoundingMode.HALF_UP);
	}

	public String getMaxLevel() {
		return maxLevel;
	}

	public void setMaxLevel(String maxLevel) {
		this.maxLevel = maxLevel;
	}

	public String getLevel() {
		return level;
	}

	public void setLevel(String level) {
		this.level = level;
	}

	public String getProgress() {
		return progress;
	}

	public void setProgress(String progress) {
		this.progress = progress;
	}

	
	public Integer getCourseId() {
		return courseId;
	}

	public void setCourseId(Integer courseId) {
		this.courseId = courseId;
	}

	public Integer getChapterId() {
		return chapterId;
	}

	public void setChapterId(Integer chapterId) {
		this.chapterId = chapterId;
	}

	public Integer getConsumedLectures() {
		return consumedLectures;
	}

	public void setConsumedLectures(Integer consumedLectures) {
		this.consumedLectures = consumedLectures;
	}

	public Integer getBalanceLectures() {
		return balanceLectures;
	}

	public void setBalanceLectures(Integer balanceLectures) {
		this.balanceLectures = balanceLectures;
	}

	public Integer getFrozenLectures() {
		return frozenLectures;
	}

	public void setFrozenLectures(Integer frozenLectures) {
		this.frozenLectures = frozenLectures;
	}

	public BigDecimal getListenScore() {
		return listenScore;
	}

	public void setListenScore(BigDecimal listenScore) {
		this.listenScore = listenScore;
	}

	public BigDecimal getOralScore() {
		return oralScore;
	}

	public void setOralScore(BigDecimal oralScore) {
		this.oralScore = oralScore;
	}

	public BigDecimal getReadScore() {
		return readScore;
	}

	public void setReadScore(BigDecimal readScore) {
		this.readScore = readScore;
	}

	public Integer getCommentCount() {
		return commentCount;
	}

	public void setCommentCount(Integer commentCount) {
		this.commentCount = commentCount;
	}

	public BigDecimal getListenChange() {
		return listenChange;
	}

	public void setListenChange(BigDecimal listenChange) {
		this.listenChange = listenChange;
	}

	public BigDecimal getOralChange() {
		return oralChange;
	}

	public void setOralChange(BigDecimal oralChange) {
		this.oralChange = oralChange;
	}

	public BigDecimal getReadChange() {
		return readChange;
	}

	public void setReadChange(BigDecimal readChange) {
		this.readChange = readChange;
	}

	public Map<String, Object> getTask() {
		return task;
	}

	public void setTask(Map<String, Object> task) {
		this.task = task;
	}
}
